<?php

class VerifyController extends BaseController {

    public function __construct(){

    }

    public function Tess(){

        include( app_path()."/libraries/Snoopy.class.php");
		ini_set("max_execution_time" , 18000);

		// if( Input::has('username') || Input::has('password') )
		// 	return Response::json( ['error'=>true , 'message'=>'缺少重要参数'] , 200 );

		// $username = Input::get('username');
		// $password = Input::get('password');

		$agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36';//伪装浏览器
		$library_ip = "202.206.242.99";
		$library_host = "http://202.206.242.99/";
		$library_pic_router = "reader/captcha.php";
		$library_login_router = "reader/login.php";

		$snoopy = new Snoopy;
		$submit_url = $library_host.$library_pic_router;

		//获取cookie
		$snoopy->host = $library_ip;
		$snoopy->agent = $agent;
		$snoopy->fetch($submit_url);
		$snoopy->setcookies();
		$cookie = $snoopy->cookies;
		//超时返回
		if ($snoopy->status != '200' || $snoopy->timed_out)
	    	return Response::json( ['error'=>true , 'message'=>'获取验证码失败'] , 200 );

		$result = $snoopy->results;

		$user_id = Session::has('user_id') ? Session::get('user_id') : 0;
		$filename = $user_id.'.png';
        $filepath = '/home/yantu/Documents/www/library/public/temp_img/'.$filename;

    	$size=strlen($result); //文件大小

    	$fp2 = @fopen( $filepath , 'a' );
    	fwrite( $fp2 , $result );
    	fclose( $fp2 );


        $output = shell_exec('tesseract '.$filepath.' /home/yantu/Documents/www/library/public/temp_text/'.$user_id.'.txt -l eng -psm 7');
        $content = file_get_contents( '/home/yantu/Documents/www/library/public/temp_text/'.$user_id.'.txt.txt' );
        $content = trim($content);

        shell_exec('rm -rf '.$filepath);    //查完即删

        var_dump($content);
    }

}

?>
